﻿''' <summary>
''' シーケンスキー（SQLServer2012）属性
''' </summary>
''' <remarks></remarks>
Public Class SQLServerSequenceKeyAttribute
    Inherits KeyAttribute

    Public Sub New(ByVal sequenceName As String)
        Me.SequenceName = sequenceName
    End Sub

    Public Property SequenceName As String

    Public Overrides Function CreateKeyQueryBeforeSave(trn As System.Data.IDbTransaction) As System.Data.IDbCommand
        Dim cmd As IDbCommand = trn.Connection.CreateCommand
        cmd.Transaction = trn
        cmd.CommandText = String.Format("SELECT NEXT VALUE FOR {0}", Me.SequenceName)
        Return cmd
    End Function

End Class
